import java.util.Arrays;

/*
剑指 Offer 45. 把数组排成最小的数
 */
public class Offer45 {

  public static void main(String[] args) {
    System.out.println(new Offer45().minNumber(new int[]{3, 30, 34, 5, 9}));
  }

  public String minNumber(int[] nums) {
    String[] strs = new String[nums.length];
    for (int i = 0; i < nums.length; i++) {
      strs[i] = String.valueOf(nums[i]);
      Arrays.sort(strs,(x,y) -> (x + y).compareTo(y + x));
    }
    StringBuilder stringBuilder = new StringBuilder();
    for (String str : strs) {
      stringBuilder.append(str);
    }
    return stringBuilder.toString();
  }
}
